
// 接口文档
// https://console-docs.apipost.cn/preview/2637807e12f32c97/ecbfe93b1b5aeddd?target_id=3f37b2fb-54e4-4c6a-bd88-49b9634cfd4c#3f37b2fb-54e4-4c6a-bd88-49b9634cfd4c

 // 获取token值
import Vue from 'vue';

export default (url, method, params = {}, hasToken = true) => { // 传参： 接口url，  method类型， params参数
const token = uni.getStorageSync('qlbToken');

const baseUrl = Vue.prototype.$imgUrl;
let data={};

	data=params

	return new Promise((resolve, reject) => {
		uni.request({
				method: method,
				url: baseUrl + url,
				data,
				header: {
					// 'Content-Type':'multipart/form-data',
					'Authori-zation':token
				}
				,success:(res) => {
					
					resolve(res.data);
				
				},fail:(fal) => {
					// 请求失败后的处理
					reject(fal);
				},
				complete:(com)=>{
					if(com.data.code==401){
						uni.showToast({
							title:com.data.message,
							icon:"none",
							duration:2000,
						})
						uni.removeStorageSync('qlbToken');
						setTimeout(function(){
							uni.switchTab({
								url:'/pages/index/my'
							})
						},2500);
						return;
					}
					if(com.data.code!=200){
						
						
						uni.showModal({
							title: '提示',
							content: com.data.message,
							showCancel: false,
							success() {
								
							}
						});
						
						
						return;
					}
				}
			})
	})

}


